local joyex__tianxiang = fk.CreateSkill {

  name = "joyex__tianxiang",

  tags = {  },

}



joyex__tianxiang:addEffect(fk.DamageInflicted, {
  name = "joyex__tianxiang",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(joyex__tianxiang.name) and target == player
  end,
  on_cost = function(self, event, target, player, data)
    local tar, card =  player.room:askForChooseCardAndPlayers(player, table.map(player.room:getOtherPlayers(player), function (p)
      return p.id end), 1, 1, ".|.|heart|hand", "#joyex__tianxiang-choose", joyex__tianxiang.name, true)
    if #tar > 0 and card then
      event:setCostData(self, {tar[1], card})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self)[1])
    room:throwCard(event:getCostData(self)[2], joyex__tianxiang.name, player, player)
    local damage = table.simpleClone(data)
    damage.to = to
    room:damage(damage)
    if not to.dead then
      local n = 1
      if not player.dead then
        local choice = room:askForChoice(player, {"1", tostring(math.min(to:getLostHp(), 5))}, joyex__tianxiang.name, "#joyex__tianxiang-choice::"..to.id)
        n = tonumber(choice)
      end
      to:drawCards(n, joyex__tianxiang.name)
    end
    return true
  end,
})

return joyex__tianxiang